package drogados.planingpoker;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Gallery g = (Gallery) findViewById(R.id.gallery);
        g.setAdapter(new ImageAdapter(this));

        g.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent,
                View v, int position, long id) {
            	Toast.makeText(MainActivity.this, "" + (position+1),
                    Toast.LENGTH_SHORT).show();
                
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public class ImageAdapter extends BaseAdapter {
    	   int mGalleryItemBackground;
    	   private Context mContext;

    	   private Integer[] mImageIds = {
    	           R.drawable.carta,
    	           R.drawable.carta2,
    	           R.drawable.carta3,
    	           R.drawable.carta4,
    	           R.drawable.carta5,
    	   };

    	   public ImageAdapter(Context c) {
    	       mContext = c;
    	       TypedArray a = obtainStyledAttributes(R.styleable.Theme);
    	       mGalleryItemBackground = a.getResourceId(
    	         R.styleable.Theme_android_galleryItemBackground,
    	                   0);
    	       a.recycle();
    	   }

    	   public int getCount() {
    	       return mImageIds.length;
    	   }

    	   public Object getItem(int position) {
    	       return position;
    	   }

    	   public long getItemId(int position) {
    	       return position;
    	   }

    	   public View getView(int position,
    	       View convertView, ViewGroup parent) {
    	       ImageView i = new ImageView(mContext);

    	       i.setImageResource(mImageIds[position]);
    	       i.setLayoutParams(new Gallery.LayoutParams(195, 300));
    	       i.setScaleType(ImageView.ScaleType.FIT_XY);
    	       i.setBackgroundResource(mGalleryItemBackground);

    	       return i;
    	   }
    	}
}
